/*
 * @Author: your name
 * @Date: 2021-09-30 19:57:15
 * @LastEditTime: 2021-09-30 21:59:06
 * @LastEditors: Please set LastEditors
 * @Description: P1024	[NOIP2001 提高组] 一元三次方程求解 入门
 * https://www.luogu.com.cn/problem/P1024              
 * @FilePath: \luogu\1.6二分查找\P1024\main.cpp
 */


/*
    idea:
    a*x*x*x + b*x*x + c*x + d = 0
    f(x)计算函数
    先找一个根,二分判断条件 if : f(left)*f(mid) <=0 [left,mid] else (mid,right]
    开区间+0.01 ?
    然后把求得的第一个根当中left或者right继续求解
*/
#include<iostream>
#include "equation.h"

using namespace std;


int main(){
    double a,b,c,d;
    a = 1;
    b = -5;
    c = -4;
    d = 20;

    cout << "comein" << endl;
    //方程组对象
    Equation * e = new Equation(a,b,c,d);

    // cout << e->f(0) << endl; //20
    // cout << e->f(1) << endl; //12


    for(int i=-100; i<100; i++){
        //对i~i+1进行检查
        if(e->f(i) * e->f(i+0.99) <= 0){
            // cout << "i=" << i << endl;
            //解在(i,i+1)
            double result = e->binarySearch(i,i+0.99);
            cout << result << endl;
        }
    }
    cout << "comeout" << endl;
    return 0;
}
